package com.df.ez_game.server;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ServerManager {
    private static Map<String,ServerNode> serverNodeMap = new ConcurrentHashMap<>();

    public static void register(ServerNode serverNode){
        ServerNode old = serverNodeMap.get(serverNode.getName());
        if(old==null){
            serverNodeMap.put(serverNode.getName(),serverNode);
            return;
        }
        if(serverNode==old){
            return;
        }
        throw new RuntimeException("已经存在相同的服务器节点了："+serverNode.getName());
    }
    public static void unRegister(String name){
        serverNodeMap.remove(name);
    }

    public static ServerNode getServerNode(String name){
        return serverNodeMap.get(name);
    }
}
